﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PHMEE
{
    public static class TdTableHelper
    {
        public static List<string> GetColumnsForSuperTable(string superTableName)
        {
            var classes = Assembly.GetExecutingAssembly()
                .GetTypes()
                .Where(t => t.IsClass && t.IsAbstract && t.IsSealed)
                .Where(t => t.GetCustomAttribute<SuperTableAttribute>()?.TableName == superTableName);

            var columns = new List<string>();

            foreach (var @class in classes)
            {
                var fields = @class.GetFields(BindingFlags.Public | BindingFlags.Static)
                                   .Where(f => f.IsLiteral && !f.IsInitOnly); // 常量字段
                columns.AddRange(fields.Select(f => f.GetValue(null)?.ToString()));
            }

            return columns;
        }
    }
}
